<?php
class myUtil
{
    function generatePager ($per_page, $total_count, $page = NULL, $extraVars = array(), $path)
    {
        require_once ("Pager.class.php");
        $pager_opt = array(
            "totalItems"   => $total_count,
            "perPage"      => $per_page,
            "urlVar"       => "page",
            "delta"        => 4,
            "extraVars"    => $extraVars,
            "path"    => $path
        );

        $pager = new Pager_sliding($pager_opt);
        list($list_start, $list_end) = $pager->getOffsetByPageId();

        // ページャー作成
        $page_links = $pager->getLinks();
        $num_e = ($per_page > $total_count)     ? $total_count  : $per_page;
        if ($page === NULL || $page == 1) {
            $nav = array("num_s" => 0, "num_e" => $num_e);
        } else {
            $num_s = $page * $per_page - ($per_page);
            $nav = array("num_s" => $num_s, "num_e" => $num_e);
        }

        $nav["back"] = preg_replace("/memberadm\.php/", "", $page_links["back"]);
        $nav["next"] = preg_replace("/memberadm\.php/", "", $page_links["next"]);
        $nav["pages"] = preg_replace("/memberadm\.php/", "", rtrim($page_links["pages"]," "));
        $nav["all"] = preg_replace("/memberadm\.php/", "", $page_links["all"]);
        $nav["total"] = $total_count;
        $nav["start"] = $list_start;
        $nav["end"] = $list_end;

        return $nav;
    }

    /**
     * 画像の拡張子を取得
     *
     * @return string
     */
    public static function getFileExtId($filePath)
    {
        // @ はエラー制御演算子と呼ばれるもので、エラーがあってもメッセージを出さない。
        $info = @getimagesize($filePath);
        return  $info[2];
    }
    public static function getFileExt($filePath)
    {
        $id = myUtil::getFileExtId($filePath);
        $image_types = array("", "gif", "jpg", "png", "tif" ,"","bmp");

        return  ".".$image_types[$id];
    }
}